from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, validators
from .validators import Unique, EmailValidator, StrongPassword
from .models import User

class LoginForm(FlaskForm):
    username = StringField('用户名', [
        validators.DataRequired(message="用户名不能为空"),
        validators.Length(min=3, max=50,message='用户名长度需在3-50字符之间')
    ])
    password = PasswordField('密码', [
        validators.DataRequired(),
        validators.Length(min=8)
    ])
    captcha = StringField("验证码")

class RegisterForm(FlaskForm):
    username = StringField('用户名', [
        validators.DataRequired(message="用户名不能为空"),
        validators.Length(min=3, max=50,message='用户名长度需在3-50字符之间'),
        Unique(User, User.username, '用户名已存在')
    ])
    email = StringField('邮箱', [
        validators.DataRequired(message="邮箱不能为空"),
        validators.Length(min=6, max=120, message="邮箱长度需要在6-120之间"),
        EmailValidator()
    ])
    password = PasswordField('密码', [
        validators.DataRequired(message="密码不能为空"),
        validators.Length(min=8, message="密码长度不能低于8位"),
        validators.EqualTo('confirm', message='两次密码不一致'),
        StrongPassword()
    ])
    confirm = PasswordField('确认密码',[
        validators.DataRequired(message="确认密码不能为空"),
    ])
    captcha = StringField("验证码",[
        validators.DataRequired(message="验证码不能为空"),
    ])
    agreement = StringField("用户条约",[
        validators.DataRequired(message="用户条约需要确认"),
    ])


class ForgotPasswordForm(FlaskForm):
    email = StringField('邮箱', [
        validators.DataRequired(message="邮箱不能为空"),
        validators.Length(min=6, max=120, message="邮箱长度需要在6-120之间"),
        EmailValidator()
    ])
    captcha = StringField("验证码")

class SetPasswordForm(FlaskForm):
    password = PasswordField('密码', [
        validators.DataRequired(message="密码不能为空"),
        validators.Length(min=8, message="密码长度不能低于8位"),
        validators.EqualTo('confirm', message='两次密码不一致'),
        StrongPassword()
    ])
    confirm = PasswordField('确认密码',[
        validators.DataRequired(message="确认密码不能为空"),
    ])
    email = StringField('邮箱', [
        validators.DataRequired(message="邮箱不能为空"),
        validators.Length(min=6, max=120, message="邮箱长度需要在6-120之间"),
        EmailValidator()
    ])
